home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / sbin / service < prev    next >
Text File  |  2009-10-19  |  5KB  |  139 lines

  1. #!/bin/sh
  2.  
  3. ###########################################################################
  4. # /usr/bin/service
  5. #
  6. # A convenient wrapper for the /etc/init.d init scripts.
  7. #
  8. # This script is a modified version of the /sbin/service utility found on
  9. # Red Hat/Fedora systems (licensed GPLv2+).
  10. #
  11. # Copyright (C) 2006 Red Hat, Inc. All rights reserved.
  12. # Copyright (C) 2008 Canonical Ltd.
  13. #   * August 2008 - Dustin Kirkland <kirkland@canonical.com>
  14. #
  15. # This program is free software; you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation; either version 2 of the License, or
  18. # (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program; if not, write to the Free Software
  27. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  28. #
  29. # On Debian GNU/Linux systems, the complete text of the GNU General
  30. # Public License can be found in `/usr/share/common-licenses/GPL-2'.
  31. ###########################################################################
  32.  
  33.  
  34. is_ignored_file() {
  35.     case "$1" in
  36.         skeleton | README | *.dpkg-dist | *.dpkg-old | rc | rcS | single | reboot | bootclean.sh)
  37.             return 0
  38.         ;;
  39.     esac
  40.     return 1
  41. }
  42.  
  43. VERSION="`basename $0` ver. 0.91-ubuntu1"
  44. USAGE="Usage: `basename $0` < option > | --status-all | \
  45. [ service_name [ command | --full-restart ] ]"
  46. SERVICE=
  47. ACTION=
  48. SERVICEDIR="/etc/init.d"
  49. OPTIONS=
  50.  
  51. if [ $# -eq 0 ]; then
  52.    echo "${USAGE}" >&2
  53.    exit 1
  54. fi
  55.  
  56. cd /
  57. while [ $# -gt 0 ]; do
  58.   case "${1}" in
  59.     --help | -h | --h* )
  60.        echo "${USAGE}" >&2
  61.        exit 0
  62.        ;;
  63.     --version | -V )
  64.        echo "${VERSION}" >&2
  65.        exit 0
  66.        ;;
  67.     *)
  68.        if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
  69.           cd ${SERVICEDIR}
  70.           for SERVICE in * ; do
  71.             case "${SERVICE}" in
  72.               functions | halt | killall | single| linuxconf| kudzu)
  73.                   ;;
  74.               *)
  75.                 if ! is_ignored_file "${SERVICE}" \
  76.             && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
  77.                         if ! grep -qs "\Wstatus)" "$SERVICE"; then
  78.                           #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
  79.                           echo " [ ? ]  $SERVICE" 1>&2
  80.                           continue
  81.                         else
  82.                           out=$(env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
  83.                           if [ "$?" = "0" -a -n "$out" ]; then
  84.                             #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
  85.                             echo " [ + ]  $SERVICE"
  86.                             continue
  87.                           else
  88.                             #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
  89.                             echo " [ - ]  $SERVICE"
  90.                             continue
  91.                           fi
  92.                         fi
  93.                   #env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
  94.                 fi
  95.                 ;;
  96.             esac
  97.           done
  98.           exit 0
  99.        elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
  100.           SERVICE="${1}"
  101.           if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
  102.             env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" stop
  103.             env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" start
  104.             exit $?
  105.           fi
  106.        elif [ -z "${SERVICE}" ]; then
  107.          SERVICE="${1}"
  108.        elif [ -z "${ACTION}" ]; then
  109.          ACTION="${1}"
  110.        else
  111.          OPTIONS="${OPTIONS} ${1}"
  112.        fi
  113.        shift
  114.        ;;
  115.    esac
  116. done
  117.  
  118. if [ -r "/etc/init/${SERVICE}.conf" ]; then
  119.    # Upstart configuration exists for this job
  120.    case "${ACTION}" in
  121.       start|stop|restart|status|reload)
  122.          # Action is a valid upstart action
  123.          exec ${ACTION} ${SERVICE} ${OPTIONS}
  124.       ;;
  125.       force-reload)
  126.          # Upstart just uses reload for force-reload
  127.          exec reload ${SERVICE} ${OPTIONS}
  128.       ;;
  129.    esac
  130. fi
  131.  
  132. # Otherwise, use the traditional sysvinit
  133. if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
  134.    exec env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" ${ACTION} ${OPTIONS}
  135. else
  136.    echo "${SERVICE}: unrecognized service" >&2
  137.    exit 1
  138. fi
  139.